﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DelonixRegiaHMSys.Core.Services;
using DelonixRegiaHMSys.Infrastructure.Data;
using DelonixRegiaHMSys.Core.Models;


namespace DelonixRegiaHMSys.UI.WebForms
{
    public partial class CheckInManagement : System.Web.UI.Page
    {
        string userID;
        protected void Page_Load(object sender, EventArgs e)
        {
            userID = Request.QueryString["UserID"];
            if (!Page.IsPostBack)
            {
                string ID = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                string strid = "";
                Random rnd = new Random();
                for (int i = 0; i <= 3; i++)
                {
                    int randomint = rnd.Next(0, ID.Length - 1);
                    strid += ID.Substring(randomint, 2);
                }
                lblcheckinID.Text = strid;
            }
            lblguestID.Text = Request.QueryString["GuestID"];


        }

        protected void btncinext_Click(object sender, EventArgs e)
        {
            string CheckInID = lblcheckinID.Text;
            string GuestID = lblguestID.Text;
            string ReservationID = "null";
            string UserID = userID;
            int NumOfAdults = Convert.ToInt32(ddlnumOfAdults.SelectedValue);
            int NumOfChildren = Convert.ToInt32(ddlnumOfChildren.SelectedValue);
            DateTime CheckInDateTime = DateTime.Now;
            DateTime DesiredCheckOutDateTime = Convert.ToDateTime(tbxdesirecheckouttime.Text);
            string RoomType = rblroomType.SelectedValue;
            string BedType = rblbedType.SelectedValue;
            string SmokingOrNot = rblsmokingOrNot.SelectedValue;
            string LateCheckOutRequest = rbllateCheckOutReq.SelectedValue;
            string PaymentMode = rblpaymentMode.SelectedValue;
            string AddRemarks = tbxaddRemarks.Text;
            if (rblpaymentMode.SelectedValue == "CreditCard")
            {
                GuestCreditCardDetails gccd = new GuestCreditCardDetails();
                gccd.GuestID = lblguestID.Text;
                gccd.CreditCardNum = tbxcreditCardNum.Text;
                gccd.CardHolderName = tbxcardHolderName.Text;
                gccd.CardType = ddlcardType.SelectedValue;
                gccd.CardExpirationDate = Convert.ToDateTime(tbxexpiretime.Text);

                var gccdservice = new gccdServices(new EfGuestCreditCardDetails());
                gccdservice.AddCreditCardDetail(gccd);
            }

            string queryString = "UserID=" + UserID + "&CheckInID=" + CheckInID + "&GuestID=" + GuestID + "&ReservationID=" + ReservationID +
                "&NumOfAdults=" + NumOfAdults + "&NumOfChildren=" + NumOfChildren + "&CheckInDateTime=" + CheckInDateTime + "&DesiredCheckOutDateTime=" + DesiredCheckOutDateTime +
                "&RoomType=" + RoomType + "&BedType=" + BedType + "&SmokingOrNot=" + SmokingOrNot + "&LateCheckOutReq=" + LateCheckOutRequest + "&PaymentMode=" + PaymentMode +
                "&AddRemarks=" + AddRemarks;

            Server.Transfer("~/WebForms/RRandCIModule/RoomSelection.aspx?" + queryString);
        }

        protected void rblpaymentMode_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (rblpaymentMode.SelectedValue == "CreditCard")
            {
                pnl.Visible = true;
            }
            else
            {
                pnl.Visible = false;
            }
        }

    }
}